<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="推广芳疗师设置">
          <!-- <serveSelect @selectClick="selectClick" :value="model.agencyCode"></serveSelect> -->
          <a-select
            v-model:value="value"
            show-search
            placeholder="input search text"
            style="width: 200px"
            :default-active-first-option="false"
            :show-arrow="false"
            :filter-option="false"
            :not-found-content="null"
            :options="datas"
            @search="handleSearch"
            @change="handleChange"
          ></a-select>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
import { xhdjCoachInfoList, xhdjAppCoachOrderChangeCoach } from '@/api/manage.js'
import { httpAction } from '@/api/manage'
export default {
  name: 'Xhdjgenhuanjishi',
  data () {
    return {
      title: '操作',
      visible: false,
      model: {}, //所有数据
      value: '',
      datas: [],
      from: {
        parentCoachId: null,
        id: null
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        agencyCode: [{ required: true, message: '请选择更换技师', trigger: 'change' }]
      },
      url: {
        // add: '/material/xhdjMaterialPick/add',
        // edit: '/material/xhdjMaterialPick/edit'
      }
    }
  },
  created () {
    this.datas = []
    this.handleSearch()
  },
  methods: {
    // 输入的值
    async handleSearch (value) {
      this.datas = []
      console.log(value)
      const res = await xhdjCoachInfoList({
        coachName: value
      })
      if (res.code == 200) {
        res.result.records.forEach(item => {
          this.datas.push({
            label: item.coachName,
            value: item.id
          })
        })
      }
    },

    handleChange (value) {
      this.from.parentCoachId = value
    },
    add () {
      //初始化默认值
      this.edit({})
    },
    edit (record) {
      this.model = Object.assign({}, record)
      console.log(this.model)
      this.from.id = this.model.id
      this.visible = true
    },
    close () {
      this.from = {}
      this.model = {}
      this.value = ''
      this.$emit('close')
      this.visible = false
      this.$refs.form.clearValidate()
    },
    async handleOk () {
      const that = this
      console.log(this.from)
      if (this.from.id == this.from.parentCoachId) return this.$message.warning('不能选择自己！')
      let httpurl = '/xhdjCoachInfo/edit'
      let method = 'put'
      httpAction(httpurl, this.from, method)
        .then(res => {
          if (res.success) {
            that.$message.success(res.message)
            that.$emit('ok')
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
          that.close()
        })
    },

    handleCancel () {
      this.close()
    }
  }
}
</script>

<style lang="less" scoped></style>
